﻿@page "/EmptyPage"
@inject PickingServer pickingServer
@using System.ComponentModel
@using AntDesign.TableModels
@using ShanjinPDAUI.ModelEntity
@inject ModalService _modalService
@inject MessageService _message
@inject EmptyCache_EntityServer emptyCache_EntityServer
<h3>主机领取空卷</h3>
<div>
    <Row>
        <Col Span="24">请选择主机</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@Machines"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@Machineselet"
                ValueName="@nameof(Machine_Entity.Devid)"
                LabelName="@nameof(Machine_Entity.Remark)">
        </Select>
        </Col>
    </Row>
@*    <Row>
        <Col Span="24">
        <label>宽幅</label>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@width" />
        </Col>
    </Row>*@
    <Row>
        <Col Span="24">
        <label>是否大卷</label>
        </Col>
    </Row>

    <Row>
        <Col Span="8" Push="8">
        <Switch style="width:100%" @bind-Value="@Flag"></Switch>
        </Col>
    </Row>
    <br>
    <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat">领空轴</Button>
        </Col>
    </Row>
    <br>

    <Row>
        <Col Span="24">
     @*   <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creatnobaked">生箔下料，无需烘烤</Button>*@
        </Col>
    </Row>
    <br>
    <Row>
        <Col Span="24">
      @*  <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creatnotobebaked">生箔下料，无可用烘箱</Button>*@
        </Col>
    </Row>
</div>

@code {
    ObservableCollection<Machine_Entity> Machines { get; set; } = new ObservableCollection<Machine_Entity>();
    int Machineselet { get; set; } = 0;
    bool Flag { get; set; } = false;
    int width;
    protected override async Task OnInitializedAsync()
    {
        var machines = await pickingServer.GetMachine();
        if (machines != null)
        {
            Machines.Clear();
            foreach (var item in machines)
            {
                Machines.Add(item);
            }
        }
   
        base.OnInitialized();
    }
    private async Task Creat()
    {
        _modalService.Confirm(new ConfirmOptions()
            {
                Title = "提示",
                Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            Content = "是否提交？",
            OkText = "确认",
            OnOk = async (e) =>
            {
                var Machine= Machines.FirstOrDefault(x => x.Devid == Machineselet);
                if (Machine!=null)
                {
                    if (Machine.IsLk)
                    {
                        //如果是涂层领空卷芯
                        if (Machine.MESName.Contains("K3PCOT001_18") || Machine.MESName.Contains("K3PCOT002_18"))
                        {
                            int type = 0;
                            if (Machine.MESName.Contains("K3PCOT001_18"))
                            {
                                type = 1;
                            }
                            else if (Machine.MESName.Contains("K3PCOT002_18"))
                            {
                                type = 2;
                            }
                            var emptyCahe = await emptyCache_EntityServer.GetEmptyCache(type);
                            if (emptyCahe == null)
                            {
                                
                                await _message.Info($"取空卷芯任务：未找到有空卷芯的缓存架");
                                return;
                            }
                            var   outBoundresult = await pickingServer.EmptyPICK(Machine, Flag, emptyCahe.Deviceid);
                            await _message.Info(outBoundresult);
                            return;
                        }
                        //立库领料
                        var b = await pickingServer.EmptyPICK(Machine, Flag);
                        await _message.Info(b);
                    }
                    //else
                    //{
                    //    //拆包间领料
                    //    if (Machine.UnpackingAre!=0)
                    //    {
                    //      var bb = await pickingServer.GetuNPK();
                    //        var bbb = bb.FirstOrDefault(x => x.Deviceid == Machine.UnpackingAre);
                    //        if (bbb != null)
                    //        {
                    //            var b = await pickingServer.PickCreatFromUnpak(Machine, width, bbb, Flag);
                    //            await _message.Info(b);
                    //        }
                    //        else
                    //        {
                    //            await _message.Info("拆包间与绑定主机绑定不匹配");
                            
                    //        }

                    //    }
                    //}
                }

            },
            CancelText = "取消"
        });


    }


}

